/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ohtu;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class EventContainer implements Serializable {
	// Maybe should be hashset or something

	private ArrayList<Event> events;

	public EventContainer() {
		events = new ArrayList<Event>();
	}

	public void add(Event event) {
		events.add(event);
	}

	public void remove(Event event) {
		events.remove(event);
	}

	public void clear() { events.clear(); }

	public ArrayList<Event> getOnInterval(Date start, Date end) {
		ArrayList<Event> ret = new ArrayList<Event>();
		Calendar temp = Calendar.getInstance();
		for (Event event : events) {
			if (event.isRecurring()) {
				temp.setTime(start);
				temp.set(Calendar.DAY_OF_WEEK, event.getStartDate().get(Calendar.DAY_OF_WEEK));
				temp.set(Calendar.HOUR_OF_DAY, event.getStartDate().get(Calendar.HOUR_OF_DAY));
				if (temp.getTime().after(start) && temp.getTime().before(end)) {
					ret.add(event);
				}
			} else if (event.getStartDate().getTime().after(start) && event.getStartDate().getTime().before(end)) {
				ret.add(event);
			}
		}
		return ret;
	}

	public ArrayList<Event> getAllEvents() {
		return events;
	}
}
